<?php

declare(strict_types=1);

namespace Modules\User\Enums;

/**
 * 操作类型枚举
 */
enum ActionType: string
{
    case LOGIN = 'login';
    case LOGOUT = 'logout';
    case CREATE = 'create';
    case UPDATE = 'update';
    case DELETE = 'delete';
    case BATCH_DELETE = 'batch_delete';
    case VIEW = 'view';
    case EXPORT = 'export';
    case IMPORT = 'import';
    case UPLOAD = 'upload';
    case DOWNLOAD = 'download';
    case ENABLE = 'enable';
    case DISABLE = 'disable';
    case RESET_PASSWORD = 'reset_password';
    case CHANGE_PASSWORD = 'change_password';
    case ASSIGN_ROLE = 'assign_role';
    case REVOKE_ROLE = 'revoke_role';
    case GRANT_PERMISSION = 'grant_permission';
    case REVOKE_PERMISSION = 'revoke_permission';
    case BACKUP = 'backup';
    case RESTORE = 'restore';
    case CLEAR_CACHE = 'clear_cache';
    case SYNC = 'sync';
    case SEND_EMAIL = 'send_email';
    case SEND_SMS = 'send_sms';
    case AUDIT = 'audit';
    case APPROVE = 'approve';
    case REJECT = 'reject';

    /**
     * 获取操作显示名称
     */
    public function label(): string
    {
        return match ( $this ) {
            self::LOGIN => '登录',
            self::LOGOUT => '退出',
            self::CREATE => '创建',
            self::UPDATE => '更新',
            self::DELETE => '删除',
            self::BATCH_DELETE => '批量删除',
            self::VIEW => '查看',
            self::EXPORT => '导出',
            self::IMPORT => '导入',
            self::UPLOAD => '上传',
            self::DOWNLOAD => '下载',
            self::ENABLE => '启用',
            self::DISABLE => '禁用',
            self::RESET_PASSWORD => '重置密码',
            self::CHANGE_PASSWORD => '修改密码',
            self::ASSIGN_ROLE => '分配角色',
            self::REVOKE_ROLE => '撤销角色',
            self::GRANT_PERMISSION => '授权',
            self::REVOKE_PERMISSION => '撤销权限',
            self::BACKUP => '备份',
            self::RESTORE => '恢复',
            self::CLEAR_CACHE => '清除缓存',
            self::SYNC => '同步',
            self::SEND_EMAIL => '发送邮件',
            self::SEND_SMS => '发送短信',
            self::AUDIT => '审核',
            self::APPROVE => '批准',
            self::REJECT => '拒绝',
        };
    }

    /**
     * 获取操作图标
     */
    public function icon(): string
    {
        return match($this) {
            self::LOGIN => 'el-icon-user',
            self::LOGOUT => 'el-icon-switch-button',
            self::CREATE => 'el-icon-plus',
            self::UPDATE => 'el-icon-edit',
            self::DELETE, self::BATCH_DELETE => 'el-icon-delete',
            self::VIEW => 'el-icon-view',
            self::EXPORT => 'el-icon-download',
            self::IMPORT => 'el-icon-upload2',
            self::UPLOAD => 'el-icon-upload',
            self::DOWNLOAD => 'el-icon-download',
            self::ENABLE => 'el-icon-check',
            self::DISABLE => 'el-icon-close',
            self::RESET_PASSWORD, self::CHANGE_PASSWORD => 'el-icon-key',
            self::ASSIGN_ROLE, self::REVOKE_ROLE => 'el-icon-user-solid',
            self::GRANT_PERMISSION, self::REVOKE_PERMISSION => 'el-icon-lock',
            self::BACKUP => 'el-icon-folder-opened',
            self::RESTORE => 'el-icon-refresh',
            self::CLEAR_CACHE => 'el-icon-delete-solid',
            self::SYNC => 'el-icon-refresh',
            self::SEND_EMAIL => 'el-icon-message',
            self::SEND_SMS => 'el-icon-mobile-phone',
            self::AUDIT, self::APPROVE, self::REJECT => 'el-icon-document-checked',
        };
    }

    /**
     * 获取操作颜色类型
     */
    public function colorType(): string
    {
        return match($this) {
            self::LOGIN => 'success',
            self::LOGOUT => 'info',
            self::CREATE => 'primary',
            self::UPDATE => 'warning',
            self::DELETE, self::BATCH_DELETE => 'danger',
            self::VIEW => 'info',
            self::EXPORT, self::IMPORT => 'success',
            self::UPLOAD, self::DOWNLOAD => 'primary',
            self::ENABLE => 'success',
            self::DISABLE => 'danger',
            self::RESET_PASSWORD, self::CHANGE_PASSWORD => 'warning',
            self::ASSIGN_ROLE, self::GRANT_PERMISSION => 'success',
            self::REVOKE_ROLE, self::REVOKE_PERMISSION => 'danger',
            self::BACKUP, self::RESTORE => 'primary',
            self::CLEAR_CACHE, self::SYNC => 'warning',
            self::SEND_EMAIL, self::SEND_SMS => 'info',
            self::AUDIT => 'warning',
            self::APPROVE => 'success',
            self::REJECT => 'danger',
        };
    }

    /**
     * 获取所有选项
     */
    public static function options(): array
    {
        return array_map(function (self $case) {
            return [
                'value' => $case->value,
                'label' => $case->label(),
                'icon' => $case->icon(),
                'color' => $case->colorType(),
            ];
        }, self::cases());
    }

    /**
     * 获取常用操作
     */
    public static function commonActions(): array
    {
        return [
            self::CREATE,
            self::UPDATE,
            self::DELETE,
            self::VIEW,
            self::EXPORT,
            self::IMPORT,
        ];
    }

    /**
     * 获取管理操作
     */
    public static function adminActions(): array
    {
        return [
            self::ENABLE,
            self::DISABLE,
            self::RESET_PASSWORD,
            self::ASSIGN_ROLE,
            self::GRANT_PERMISSION,
            self::BACKUP,
            self::CLEAR_CACHE,
        ];
    }
}